Skip to content

Comments

Fix random_activation_in_scope panic and simplify implementation#109

Merged
HyperCodec merged 2 commits intodevfrom
copilot/sub-pr-106
Feb 20, 2026
Merged

Fix random_activation_in_scope panic and simplify implementation#109
HyperCodec merged 2 commits intodevfrom
copilot/sub-pr-106

Conversation

Copy link

Copilot AI commented Feb 20, 2026

ActivationRegistry::random_activation_in_scope would panic via usize underflow when the registry had 0 entries (len() - 1 wraps), and produce an empty range panic with exactly 1 entry. The cyclic-iterator approach was also unnecessarily convoluted.

Changes

  • src/activation.rs: Replace the cyclic-iterator loop with a direct call to activations_in_scope, assert non-empty with a descriptive message, then index randomly:
// Before
let mut iter = self.fns.values().cycle();
let num_iterations = rng.random_range(0..self.fns.len() - 1); // panics on len 0 or 1
for _ in 0..num_iterations { iter.next().unwrap(); }
let mut val = iter.next().unwrap();
while !val.scope.contains(scope) { val = iter.next().unwrap(); }
val.clone()

// After
let activations = self.activations_in_scope(scope);
assert!(!activations.is_empty(), "no activation functions registered for scope {:?}", scope);
activations[rng.random_range(0..activations.len())].clone()
  • Added # Panics doc section documenting the empty-scope assertion.

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: HyperCodec <72839119+HyperCodec@users.noreply.github.com>
Copilot AI changed the title [WIP] Update version 1.0.0 with massive rewrite Fix random_activation_in_scope panic and simplify implementation Feb 20, 2026
Copilot AI requested a review from HyperCodec February 20, 2026 15:18
@HyperCodec HyperCodec marked this pull request as ready for review February 20, 2026 15:21
@HyperCodec HyperCodec merged commit 39d363e into dev Feb 20, 2026
3 checks passed
@HyperCodec HyperCodec deleted the copilot/sub-pr-106 branch February 20, 2026 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants